<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>跟着Chat学习React之创建初始项目 | 添柴阿杰</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="最近ChatGPT比较火，我在机缘巧合下体验了一把，并且请教了“Ta”对目前Vue开发工作者的建议，得到了拓宽技能面，尝试React的回答。于是，我便起了通过对话chat,学习React的念头。 环境准备与主要流程安装 Node.js 和 npmReact 基于 Node.js 运行，因此需要先安装 Node.js 和 npm。在Node.js官网下载安装最新版本的 Node.js 后，就可以使用">
<meta property="og:type" content="article">
<meta property="og:title" content="跟着Chat学习React之创建初始项目">
<meta property="og:url" content="https://hajcker_1.gitee.io/hajcker_1.gitee.io/2023/04/07/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8B%E5%88%9B%E5%BB%BA%E5%88%9D%E5%A7%8B%E9%A1%B9%E7%9B%AE/index.html">
<meta property="og:site_name" content="添柴阿杰">
<meta property="og:description" content="最近ChatGPT比较火，我在机缘巧合下体验了一把，并且请教了“Ta”对目前Vue开发工作者的建议，得到了拓宽技能面，尝试React的回答。于是，我便起了通过对话chat,学习React的念头。 环境准备与主要流程安装 Node.js 和 npmReact 基于 Node.js 运行，因此需要先安装 Node.js 和 npm。在Node.js官网下载安装最新版本的 Node.js 后，就可以使用">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-04-07T06:12:37.000Z">
<meta property="article:modified_time" content="2023-04-09T14:50:54.103Z">
<meta property="article:author" content="添柴阿杰">
<meta property="article:tag" content="React">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/hajcker_1.gitee.io/atom.xml" title="添柴阿杰" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/hajcker_1.gitee.io/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/hajcker_1.gitee.io/css/style.css">

  
    
<link rel="stylesheet" href="/hajcker_1.gitee.io/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/hajcker_1.gitee.io/" id="logo">添柴阿杰</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/hajcker_1.gitee.io/">Home</a>
        
          <a class="main-nav-link" href="/hajcker_1.gitee.io/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/hajcker_1.gitee.io/atom.xml" title="RSS 订阅"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="搜索"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://hajcker_1.gitee.io/hajcker_1.gitee.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-跟着Chat学习React之创建初始项目" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/hajcker_1.gitee.io/2023/04/07/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8B%E5%88%9B%E5%BB%BA%E5%88%9D%E5%A7%8B%E9%A1%B9%E7%9B%AE/" class="article-date">
  <time class="dt-published" datetime="2023-04-07T06:12:37.000Z" itemprop="datePublished">2023-04-07</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      跟着Chat学习React之创建初始项目
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>最近ChatGPT比较火，我在机缘巧合下体验了一把，并且请教了“Ta”对目前Vue开发工作者的建议，得到了拓宽技能面，尝试React的回答。于是，我便起了通过对话chat,学习React的念头。</p>
<h2 id="环境准备与主要流程"><a href="#环境准备与主要流程" class="headerlink" title="环境准备与主要流程"></a>环境准备与主要流程</h2><h3 id="安装-Node-js-和-npm"><a href="#安装-Node-js-和-npm" class="headerlink" title="安装 Node.js 和 npm"></a>安装 Node.js 和 npm</h3><p>React 基于 Node.js 运行，因此需要先安装 Node.js 和 npm。在<a target="_blank" rel="noopener" href="https://nodejs.org/">Node.js官网</a>下载安装最新版本的 Node.js 后，就可以使用 npm 安装和管理依赖包了。</p>
<h3 id="创建-React-项目"><a href="#创建-React-项目" class="headerlink" title="创建 React 项目"></a>创建 React 项目</h3><p>可以使用 Create React App 工具快速创建一个基础的 React 项目。在命令行中执行以下指令：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npx create-react-app my-app</span><br></pre></td></tr></table></figure>
<p>其中 my-app 是项目名称，可以根据实际情况进行修改。执行完毕后，会在当前目录下创建一个名为 my-app 的文件夹，并安装好 React 相关的依赖包。</p>
<h3 id="进入项目目录并启动开发服务器"><a href="#进入项目目录并启动开发服务器" class="headerlink" title="进入项目目录并启动开发服务器"></a>进入项目目录并启动开发服务器</h3><p>进入刚刚创建的项目目录，并执行以下命令启动开发服务器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd my-app</span><br><span class="line">npm start</span><br></pre></td></tr></table></figure>
<p>这样就可以在浏览器中访问 <a href="http://localhost:3000,查看">http://localhost:3000,查看</a> React 应用的效果了。</p>
<h3 id="在代码编辑器中修改代码"><a href="#在代码编辑器中修改代码" class="headerlink" title="在代码编辑器中修改代码"></a>在代码编辑器中修改代码</h3><p>使用喜欢的代码编辑器打开项目目录（如 Visual Studio Code），开始编写和修改代码。React 项目的主要代码在 src 目录下，包括组件、路由配置、状态管理等内容。可以根据实际需求进行修改和开发。</p>
<h3 id="打包项目"><a href="#打包项目" class="headerlink" title="打包项目"></a>打包项目</h3><p>完成开发工作后，可以执行以下命令打包项目：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run build</span><br></pre></td></tr></table></figure>
<p>这样就会在项目目录下生成一个名为 build 的文件夹，其中包含了打包好的静态资源。上传这些资源到服务器上，即可部署 React 应用。</p>
<h2 id="一般情况下的目录结构"><a href="#一般情况下的目录结构" class="headerlink" title="一般情况下的目录结构"></a>一般情况下的目录结构</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">my-app/</span><br><span class="line">├── node_modules/</span><br><span class="line">├── public/</span><br><span class="line">│   ├── index.html</span><br><span class="line">│   └── ...</span><br><span class="line">├── src/</span><br><span class="line">│   ├── App.js</span><br><span class="line">│   ├── index.js</span><br><span class="line">│   ├── components/</span><br><span class="line">│   │   ├── Button.js</span><br><span class="line">│   │   ├── Header.js</span><br><span class="line">│   │   └── ...</span><br><span class="line">│   ├── pages/</span><br><span class="line">│   │   ├── Home.js</span><br><span class="line">│   │   ├── About.js</span><br><span class="line">│   │   └── ...</span><br><span class="line">│   ├── redux/</span><br><span class="line">│   │   ├── actions/</span><br><span class="line">│   │   ├── reducers/</span><br><span class="line">│   │   ├── store.js</span><br><span class="line">│   │   └── ...</span><br><span class="line">│   ├── utils/</span><br><span class="line">│   ├── services/</span><br><span class="line">│   ├── assets/</span><br><span class="line">│   ├── styles/</span><br><span class="line">│   └── ...</span><br><span class="line">├── .gitignore</span><br><span class="line">├── package.json</span><br><span class="line">├── README.md</span><br><span class="line">└── ...</span><br><span class="line">其中，各个文件和文件夹的作用如下：</span><br><span class="line"></span><br><span class="line">-node_modules：存放项目依赖的第三方模块。</span><br><span class="line"></span><br><span class="line">-public：存放全局静态资源，如 HTML 文件、图片等。</span><br><span class="line"></span><br><span class="line">-src：存放项目的源代码。</span><br><span class="line"></span><br><span class="line">-App.js：项目入口文件，负责渲染应用的顶层组件。</span><br><span class="line"></span><br><span class="line">-index.js：React 渲染器，负责把应用挂载到 DOM 中。</span><br><span class="line"></span><br><span class="line">-components：存放可复用的组件。</span><br><span class="line"></span><br><span class="line">-pages：存放页面级组件，负责渲染具体视图。</span><br><span class="line"></span><br><span class="line">-redux：存放 Redux 相关的代码，包括 action、reducer、store 等。</span><br><span class="line"></span><br><span class="line">-utils：存放通用的工具函数。</span><br><span class="line"></span><br><span class="line">-services：存放与后端交互的 API 接口。</span><br><span class="line"></span><br><span class="line">-assets：存放项目所需的静态资源，如图片、字体等。</span><br><span class="line"></span><br><span class="line">-styles：存放项目所需的样式文件。</span><br><span class="line"></span><br><span class="line">-.gitignore：Git 忽略文件列表。</span><br><span class="line"></span><br><span class="line">-package.json：项目配置文件，包含项目名称、版本、依赖等信息。</span><br><span class="line"></span><br><span class="line">-README.md：项目说明文档。</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://hajcker_1.gitee.io/hajcker_1.gitee.io/2023/04/07/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8B%E5%88%9B%E5%BB%BA%E5%88%9D%E5%A7%8B%E9%A1%B9%E7%9B%AE/" data-id="clh8tq38s00074gvga9beaysb" data-title="跟着Chat学习React之创建初始项目" class="article-share-link">分享</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/hajcker_1.gitee.io/tags/React/" rel="tag">React</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/hajcker_1.gitee.io/2023/04/09/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8BHooks/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">前一篇</strong>
      <div class="article-nav-title">
        
          跟着Chat学习React之学习Hooks
        
      </div>
    </a>
  
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/hajcker_1.gitee.io/tags/Node/" rel="tag">Node</a></li><li class="tag-list-item"><a class="tag-list-link" href="/hajcker_1.gitee.io/tags/React/" rel="tag">React</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/hajcker_1.gitee.io/tags/Node/" style="font-size: 10px;">Node</a> <a href="/hajcker_1.gitee.io/tags/React/" style="font-size: 20px;">React</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/hajcker_1.gitee.io/archives/2023/04/">四月 2023</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/hajcker_1.gitee.io/2023/04/14/Express%E6%90%AD%E5%BB%BA%E5%90%8E%E5%8F%B0%E6%9C%8D%E5%8A%A1/">Express搭建后台服务</a>
          </li>
        
          <li>
            <a href="/hajcker_1.gitee.io/2023/04/09/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8BHooks/">跟着Chat学习React之学习Hooks</a>
          </li>
        
          <li>
            <a href="/hajcker_1.gitee.io/2023/04/07/%E8%B7%9F%E7%9D%80Chat%E5%AD%A6%E4%B9%A0React%E4%B9%8B%E5%88%9B%E5%BB%BA%E5%88%9D%E5%A7%8B%E9%A1%B9%E7%9B%AE/">跟着Chat学习React之创建初始项目</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 添柴阿杰<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/hajcker_1.gitee.io/" class="mobile-nav-link">Home</a>
  
    <a href="/hajcker_1.gitee.io/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/hajcker_1.gitee.io/js/jquery-3.4.1.min.js"></script>



  
<script src="/hajcker_1.gitee.io/fancybox/jquery.fancybox.min.js"></script>




<script src="/hajcker_1.gitee.io/js/script.js"></script>





  </div>
</body>
</html>